/*
 *         Copyright (c) KUBOTA Corporation and HUDSON SOFT,
 *                  1994, 1995 All Rights Reserved
 *
 *  This software comprises unpublished confidential information of
 *  KUBOTA Corp. and HUDSON SOFT. It may not be used, copied or made 
 *  available to anyone, except in accordance with the license under
 *  which it is furnished.
 */
static char SccsId[] = "@(#)cubes.c	1.6	9/19/95";
#include <farl.h>
#include <agl.h>
#define OBJNum		64

unsigned int cube[] = {
#include "cubestp.h"
};

void
main()
{
     int		i, j, k;
     Material		mt1[1];
     object		o[OBJNum] = {0,}, *op;
     fix187		otrans[OBJNum][3];

     FX73init();
     FX73_cmap_i6c3();
     AGLInit();

#if 1
     /* Hidden Clear */
     FarlSetMemReg(FARL_DISPLAY_CONTROL_REG,
		   FARL_DISPLAY_CONTROL_BCM0 | FARL_DISPLAY_CONTROL_HCE);
     FarlSetPEMaskReg(0x3fff);
     FarlSetPEClearMaskReg(0x3fff);
     FarlSetPEClearColorReg(0x807);
     /**/
#endif

     FarlSetPEICMaskReg(FARL_ICMASK_I6C3);
     FarlSetTEControlReg(FARL_TE_LTEN|FARL_TE_ICM|FARL_TE_SPEN|FARL_TE_BCE);
     FarlValidateSwap();

     mt1[0].ambient  = 0x1000;
     mt1[0].diffuse  = 0x3fff;
     mt1[0].specular = 0x3fff;

     for (i = 0; i < OBJNum; i++) {
	  o[i].geometryTop    = (short*)cube;
	  o[i].geometryLength = sizeof(cube)/sizeof(int);
	  o[i].material = NULL;
     }
     o[0].material = &(mt1[0]);
     AGLSetMaterial(mt1, 1);

     for (k = 0; k < OBJNum; k++) {
	  int	t1, t2, t3;

	  t1 = k >> 2;
	  t2 = k >> 4;
	  t3 = k % 4;
	  otrans[k][0] = (t3 - 2);
	  otrans[k][1] = (2 - t1 % 4);
	  otrans[k][2] = (2 - t2);
	  otrans[k][0] *= 0x20;
	  otrans[k][1] *= 0x20;
	  otrans[k][2] *= 0x20;

	  AGLResetCamera();
	  AGLTranslateCamera(0x0, 0x0, 0x80);
	  AGLPerspectiveCamera(0xff9a);
	  for (i = 0 ; i < 3600; i += 30) {
	       op = o;
	       for (j = 0; j <= k; j++) {
		    AGLResetObj(op);
		    AGLScaleObj(op, 0x40, 0x40, 0x40);
		    AGLTranslateObj(op, otrans[j][0], otrans[j][1], otrans[j][2]);
		    AGLRotateObjY(op, i%3600);
		    AGLScaleObj(op, 0x40, 0x40, 0x40);

		    op++;
	       }
	       op  = o;
	       for (j = 0; j < k + 1 ; j++) {
		    AGLFixPutObj(op);
		    op++;
	       }

	       AGLShot();
	  }
     }
     return;
}
